﻿namespace WebPacker.Packs
{
	using System;
	using System.Collections.Generic;
	using WebPacker.Packs.Resources;

	internal static class PackHelper
	{
		public static void Dispose(this IPack pack)
		{
			if (pack == null)
			{
				throw new ArgumentNullException("pack");
			}

			var disposable = pack as IDisposable;
			
			if (disposable != null)
			{
				disposable.Dispose();
			}
		}

		internal static string[] GetContents(IEnumerable<IResource> resources)
		{
			var contents = new List<string>();

			foreach (var resource in resources)
			{
				if (resource is ICompositeResource)
				{
					contents.AddRange(GetContents(((ICompositeResource)resource).GetResources()));
				}

				contents.Add(resource.GetContent());
			}

			return contents.ToArray();
		}
	}
}
